<link rel="stylesheet" type="text/css" href="../stylesheet/style.css"/>
<?php
/*
* @author Nguyen Xuan Hong
* @copyright 2011
*/

require_once('../includes/subject.tbl.php');

if($_GET['mode'] == 'listsubject')
{
	$pClsSubject = new clsSubjectTable();	
	if($pClsSubject->avaibleSubmit()){
		$pClsSubject->loadBuffer();
		$pClsSubject->insertDB();
		echo acpredirect();
		exit();
	}
	echo $pClsSubject->createForm('Thêm chủ đề');
	
	require_once('../includes/templates.php');
	$table = new clsTable('lstsubject',array(array("ID", "1"),array("Tên chủ đề", 0),array("Sửa", 1),array("Xóa", 1)));
	$list_album = $pClsSubject->listobj($branch_id);
	foreach($list_album as $subject){
		$html_remove =      '<a href="?page=subject&mode=deletesubject&id='.$subject->value('id').'">Xóa</a>';
		$html_edit = 	'<a href="?page=subject&mode=editsubject&id='.$subject->value('id').'">Sửa</a>';	
		$table->addRow($subject->value('id'),array($subject->value('id'),$subject->value('name'),$html_edit,$html_remove));
	}
	echo $table->putHTML(true);
	exit();
}

if($_GET['mode'] == 'deletesubject'){		
	// Redefine insert
	$deleteid = sget('id');			
	$pClsSubject = new clsSubjectTable($deleteid);
	if(!$_POST['submit']){
		?>
        
	<center><div subject="notification warning">
        <span></span>
        <p><strong>Warning!</strong> 
        	<div subject="text">Bạn có muốn xóa Chủ đề này không</div> 
            <div subject="btn"><form method='post'><input type='submit' name='submit' value = 'Xóa' /></form></div>
         </p>
	</div></center>
        <?
		exit();
	}
	$pClsSubject->removeDB('id', $deleteid);
       header("location:index.php?page=subject&mode=listsubject");
	exit();
}

      if($_GET['mode'] == 'editsubject')
{
$edit = (int)sget('id');
$pClsSubject = new clsSubjectTable($deleteid);
if($pClsSubject->avaibleSubmit()){
	$pClsSubject->loadBuffer();
	$pClsSubject->updateDB('id',$edit);
	echo acpredirect('page=subject&mode=listsubject');
	exit();
}
$pClsSubject->loadDB('id',$edit);
echo $pClsSubject->createForm('Sửa chủ đề');
exit();
}
  
?> 














  